﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VRacer;
using Microsoft.Win32;

namespace VRacer.Pages
{
    /// <summary>
    /// Interaction logic for Editor.xaml
    /// </summary>
    public partial class Editor : Page
    {
        public static DependencyProperty EditedTrackProperty = DependencyProperty.Register("EditedTrack", typeof(Track), typeof(Editor));

        public Editor()
        {
            InitializeComponent();
            EditedTrack = new Track();
        }

        public Track EditedTrack
        {
            get { return (Track)GetValue(EditedTrackProperty); }
            set { SetValue(EditedTrackProperty, value); }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Track.Save(EditedTrack);
        }

        private void NewTrackMode_Checked(object sender, RoutedEventArgs e)
        {
            EditedTrack = new Track();
        }

        private void ExistingTrackMode_Checked(object sender, RoutedEventArgs e)
        {
            EditedTrack = (Track)_trackSelector.SelectedValue;
        }

        private void _trackSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            /*if(!_newTrackMode.IsChecked.Value)
                EditedTrack = (Track)e.AddedItems[0];*/
        }

        private void ButtonLoadBackground_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();
            dialog.Title = "Open background file";
            dialog.RestoreDirectory = true;
            dialog.CheckFileExists = true;
            dialog.CheckPathExists = true;

            if (dialog.ShowDialog().Value)
                EditedTrack.BackgroundFile = dialog.FileName;
        }

        private void ButtonLoadMask_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();
            dialog.Title = "Open mask file";
            dialog.RestoreDirectory = true;
            dialog.CheckFileExists = true;
            dialog.CheckPathExists = true;

            if (dialog.ShowDialog().Value)
                EditedTrack.MaskFile = dialog.FileName;
        }
    }
}
